package com.us.example.controller;

import com.us.example.domain.Msg;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by yangyibo on 17/1/18.
 */
@Controller
public class HomeController {

    @RequestMapping("/")  // 结果：通过
    public String index(Model model){
        String sellerId = SecurityContextHolder.getContext().getAuthentication().getName();
        System.out.println(sellerId);

        Msg msg =  new Msg("测试标题","测试内容","额外信息，只对管理员显示");
        model.addAttribute("msg", msg);
        return "home";
    }

    @RequestMapping("/say")
    @ResponseBody
    public String say(){

        return "I said ..";
    }

    // 测试权限，本文授予的角色是 ROLE_ADMIN  结果：通不过
    @RequestMapping("/testAdmin")
    @ResponseBody
    public String testAdmin(){

        return "testAdmin";
    }

    // 测试权限，本文授予的角色是 ROLE_ADMIN 结果：通不过
    @RequestMapping("/testOther")
    @ResponseBody
    public String testOther(){

        return "testOther";
    }

}
